package de.shortys.myhome.api.navigation;

import java.util.ArrayList;
import java.util.List;

import de.shortys.myhome.api.controller.AbstractModule;

public class ApplicationNavigator {

	// private static final Logger LOG =
	// LoggerFactory.createLogger(ApplicationNavigator.class);

	private List<AbstractModule> activeModules;

	private AbstractModule focusedModule;

	{
		activeModules = new ArrayList<AbstractModule>();
	}

	public boolean isFocused(AbstractModule module) {
		if (focusedModule != null) {
			return focusedModule.equals(module);
		}

		return false;
	}

	public void setFocused(AbstractModule module) {
		if (focusedModule != null && module != null) {
			focusedModule.defocus();
		}
		focusedModule = module;
	}

	public boolean isActive(AbstractModule module) {
		return activeModules.contains(module);
	}

	public void setActive(AbstractModule module, boolean active) {
		if (!isActive(module) && active) {
			activeModules.add(module);
		} else if (isActive(module) && !active) {
			if (isFocused(module)) {
				focusedModule = null;
			}
			activeModules.remove(module);
		}
	}

}
